package servlet.manager;

import net.sf.json.JSONObject;
import service.manager.AnnouncementService;
import service.manager.impl.AnnouncementServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * AnnouncementDelServlet
 *
 * @author 谭文斌
 * @since 2023/9/1
 */
@WebServlet("/manager/announcementDelServlet")
public class AnnouncementDelServlet extends HttpServlet {
    AnnouncementService service=new AnnouncementServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=utf8");
        PrintWriter out=resp.getWriter();
        JSONObject json = new JSONObject();

        String id=req.getParameter("id");

        int del=service.del(Integer.valueOf(id));
        if (del>0){
            json.put("code",0);
            json.put("msg","删除成功");
            json.put("data",null);
        }else {
            json.put("code",1);
            json.put("msg","删除失败");
            json.put("data",null);
        }
        out.print(json.toString());
        out.flush();
        out.close();
    }
}
